<?php
/**
 * Created by PhpStorm.
 * User: lawrence
 * Date: 07.06.2014
 * Time: 14:06
 */

class Register_Room extends CI_Controller
{
    function get_data()
    {
        $this->load->library('session');

        $data['roomid'] = $this->input->post('roomId');

        $data['startdate'] = '\'' . $this->input->post('startdate') . '\'';
        $data['enddate'] = '\'' . $this->input->post('enddate') . '\'';

        $data['pool'] = $this->input->post('pool') == 'on' ? 1 : 0;
        $data['jacuzzi'] = $this->input->post('jacuzzi') == 'on' ? 1 : 0;

        $data['massage'] = $this->input->post('massage') == 'on' ? 1 : 0;
        $data['haman'] = $this->input->post('haman') == 'on' ? 1 : 0;

        $data['sauna'] = $this->input->post('sauna') == 'on' ? 1 : 0;
        $data['salt'] = $this->input->post('salt') == 'on' ? 1 : 0;

        $data['fitness'] = $this->input->post('fitness') == 'on' ? 1 : 0;
        $data['steam_bath'] = $this->input->post('steam_bath') == 'on' ? 1 : 0;

        $this->load->model('Db_Model_Find');

        if(!$this->Db_Model_Find->find_rezerved($data['roomid'], $data['startdate'], $data['enddate']))
        {
            if($this->session->userdata('logged') == 1)
            {
                $data['window'] = 'search';
                $data['pagetitle'] = 'Rezervation Complete';
                $this->load->view('header', $data);

                $data['userid'] = $this->session->userdata('id');

                $this->Db_Model_Find->register_room($data);

                $this->load->view('room_reserved');
            }
            else
            {
                $data['window'] = 'search';
                $data['pagetitle'] = 'Login Required';
                $this->load->view('header', $data);

                $this->load->view('log_error');
            }
        }
        else
        {
            $data['window'] = 'search';
            $data['pagetitle'] = 'Rezervation Failed';
            $this->load->view('header', $data);

            $this->load->view('room_taken');
        }

        $this->load->view('footer');
    }
} 